import { defineStore } from 'pinia'
import { EncryptStorage } from "encrypt-storage";
//需注意使用stateManagementUse
export const encryptStorage = new EncryptStorage("YM1234567890", {
  stateManagementUse: true,
});
export interface NavConfig<T = any> {
    twoMenu:T,
    threeMenu:T,
    click_menu: T, //这个就是一级菜单
    all:T,
    indexActive:number,
    clickGrade:number,
    two_active_id:number,
    three_active_id:number,
    selectType:string,
    productPid:number,
    productId:number
}
export const useNavConfig = defineStore('navConfig', {
    state: (): NavConfig => {
        return {
            twoMenu:[],
            threeMenu:[],
            click_menu: [],
            all:[],
            indexActive:0,
            clickGrade:0,
            two_active_id:0,
            three_active_id:0,
            selectType:'all',
            productPid:0,
            productId:0
        }
    },
    actions: {
        dataFill(state:any) {
            this.$state.click_menu = state
        },
        setHeadNav(all:any) {
            this.$state.all = all
        },
        setTwoNav(twoMenu:any) {
            this.$state.twoMenu = twoMenu
        },
        setThreeNav(threeMenu:any) {
            this.$state.threeMenu = threeMenu
        },
        removeMenu() {
            this.twoMenu = []
            this.threeMenu = []
        },
        removeThree() {
            this.threeMenu = []
        },
        setIndex(index:number){
            this.$state.indexActive = index
        },
        setClickGrade(grade:number){
            this.$state.clickGrade = grade
        },
        setTwoActiveId(id:number){
            this.$state.two_active_id = id
        },
        setTreeActiveId(id:number){
            this.$state.three_active_id = id
        },
        setSelectType(str:string){
            this.$state.selectType = str
        },
        setProductPid(pid:number){
            this.$state.productPid = pid
        },
        setProductId(id:number){
            this.$state.productId = id
        }
    },
    persist: {
        enabled: true,
        key: "navConfig", //如果需要对存储的密钥key进行命名
        storage: encryptStorage,
        // storage: localStorage, //如果不使用加密处理
        paths: ["navConfig"],
    },
})